#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/10/26 14:36
# @Author  : HYCX-AI-LAB Liang jinhao


"""
检测是否PIN针形状
"""

from utils.MQ.message import send_message
import cv2
import json

class DetectAppearance():
    def __init__(self, MQ_send, connection_send, task_id, task_type, file):
        # MQ
        self.MQ_send = MQ_send
        self.connection_send = connection_send

        self.task_id = task_id
        self.task_type = task_type

        self.file = file

    def detect(self):
        img = cv2.imread(self.file)
        print(img.size)
        return (0, 0 ,0)

    def send_res(self):
        temp_res = self.detect()
        res = {
            "task_id": self.task_id,
            "task_type": "PIN_appearance_detect",
            "file": self.file,
            "Pin1_Up_Appearance": temp_res[0],
            "Pin2_Up_Appearance": temp_res[1],
            "Pin3_Up_Appearance": temp_res[2]
        }
        send_message(self.MQ_send, self.connection_send, json.dumps(res, ensure_ascii=False))
